package com.example.pt.dto;

/**
 * 用户传输统计DTO
 */
public class UserTransferStatsDTO {
    
    /**
     * 用户ID
     */
    private Integer userId;
    
    /**
     * 总上传量
     */
    private Long totalUploaded;
    
    /**
     * 总下载量
     */
    private Long totalDownloaded;
    
    /**
     * 总虚拟上传量
     */
    private Long totalVirtualUploaded;
    
    /**
     * 总虚拟下载量
     */
    private Long totalVirtualDownloaded;
    
    /**
     * 分享率
     */
    private Double ratio;

    public UserTransferStatsDTO() {
        this.totalUploaded = 0L;
        this.totalDownloaded = 0L;
        this.totalVirtualUploaded = 0L;
        this.totalVirtualDownloaded = 0L;
        this.ratio = 0.0;
    }
    
    public UserTransferStatsDTO(Integer userId, Long totalUploaded, Long totalDownloaded, 
                               Long totalVirtualUploaded, Long totalVirtualDownloaded) {
        this.userId = userId;
        this.totalUploaded = totalUploaded != null ? totalUploaded : 0L;
        this.totalDownloaded = totalDownloaded != null ? totalDownloaded : 0L;
        this.totalVirtualUploaded = totalVirtualUploaded != null ? totalVirtualUploaded : 0L;
        this.totalVirtualDownloaded = totalVirtualDownloaded != null ? totalVirtualDownloaded : 0L;
        calculateRatio();
    }
    
    /**
     * 计算分享率
     */
    private void calculateRatio() {
        if (totalVirtualDownloaded > 0) {
            this.ratio = (double) totalVirtualUploaded/ totalVirtualDownloaded;
            // 保留两位小数
            this.ratio = Math.round(this.ratio * 100) / 100.0;
        } else if (totalVirtualUploaded > 0) {
            this.ratio = Double.POSITIVE_INFINITY; // 无限大（只上传不下载）
        } else {
            this.ratio = 0.0;
        }
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public Long getTotalUploaded() {
        return totalUploaded;
    }

    public void setTotalUploaded(Long totalUploaded) {
        this.totalUploaded = totalUploaded;
        calculateRatio();
    }

    public Long getTotalDownloaded() {
        return totalDownloaded;
    }

    public void setTotalDownloaded(Long totalDownloaded) {
        this.totalDownloaded = totalDownloaded;
        calculateRatio();
    }
    
    public Long getTotalVirtualUploaded() {
        return totalVirtualUploaded;
    }

    public void setTotalVirtualUploaded(Long totalVirtualUploaded) {
        this.totalVirtualUploaded = totalVirtualUploaded;
    }

    public Long getTotalVirtualDownloaded() {
        return totalVirtualDownloaded;
    }

    public void setTotalVirtualDownloaded(Long totalVirtualDownloaded) {
        this.totalVirtualDownloaded = totalVirtualDownloaded;
    }

    public Double getRatio() {
        return ratio;
    }
} 